cmake_minimum_required(VERSION 3.0)

function(printmsg arg)
    message(${arg})
    foreach(var ${ARGN})
        message(${var})        
    endforeach()
    set(var_in_fun "hello")
endfunction(printmsg)

#printmsg(a b c d)
#message(${var_in_fun})  # takes an error: message called with incorrect number of arguments

# prints:
# a
# b
# c
# d


macro(print_list my_list)
  foreach(var IN LISTS my_list)
    message(${var})
  endforeach()
  set(var_in_macro "world")
endmacro()

set(my_list a b c)
set(my_list_of_numbers 1 2 3)
print_list(${my_list_of_numbers})
print_list("X;Y")

set(my_list d e f)
print_list(${my_list})

message(${var_in_macro})